-- OK (NESPOUSTET)
-- vymaz vazeb vedoucich na konstrukcni prvky formulare, ktere byly na verzi 109.2 smazany opravou Patch-2023-10000-000658
<g>
delete from a189234u10 where (ic=40247145 and u=10) or (ic=40247142 and u=10)
</g>


-- LuP   (NESPOUSTET)
<g>
-- LuP: vymaz udaju "Na vydeji ze skladovych dokladu" ve stavech zasob (NESPOUSTET)
update a10254729u10 set a39913679u10 = null where a39913679u10 is not null
update a10298574u10 set a39913681u10 = null where a39913681u10 is not null
update a10201123u10 set a39913633u10 = null where a39913633u10 is not null
update a10201123u10 set a39913637u10 = null where a39913637u10 is not null
update a10201132u10 set a39913644u10 = null where a39913644u10 is not null
update a10201132u10 set a39913640u10 = null where a39913640u10 is not null

-- LuP: vymaz udaju "Obsazeno v manipulacnich jednotkach" ve stavech zasob (NESPOUSTET)
update a38243u10 set a39911790u10 = null where a39911790u10 is not null
update a234238u10 set a39911794u10 = null where a39911794u10 is not null
update a10201123u10 set a39911792u10 = null where a39911792u10 is not null
update a10201132u10 set a39911796u10 = null where a39911796u10 is not null

-- LuP: vymaz udaju "Na vydeji z manipulacnich jednotek" ve stavech zasob (NESPOUSTET)
update a38243u10 set a39923545u10 = null where a39923545u10 is not null
update a38243u10 set a40211794u10 = null where a40211794u10 is not null
update a234238u10 set a39923547u10 = null where a39923547u10 is not null
update a234238u10 set a40211797u10 = null where a40211797u10 is not null
update a10201123u10 set a39923574u10 = null where a39923574u10 is not null
update a10201123u10 set a40211799u10 = null where a40211799u10 is not null
update a10201132u10 set a39923577u10 = null where a39923577u10 is not null
update a10201132u10 set a40211801u10 = null where a40211801u10 is not null

-- LuP: vymaz skladu u neaktivnich manipulacnich jednotek (NESPOUSTET)
delete B
from a30634680u10 as A
join a30611049u10 as B on (B.ic_a = A.ic and B.u_a = A.u)
join a30610972u10 as C on (C.ic = A.ic and C.u = A.u)
where not a30611541u10 in (1,2)

delete from a40179841u10
delete from a39923583u10
delete from a40179845u10
delete from a39923584u10
delete from a39911815u10
</g>


--LuP: naplneni disponibilniho mnozstvi ve stavech zasob s umistenim (NESPOUSTET)
<g>
select ic as IC, u as U, a10476702u10 - isnull(a10201823u10,0) - isnull(a39911796u10,0) + isnull(a39923577u10,0) as K_DISP
into #tmptable_1
from a10201132u10
where a10476702u10 is not null and a10476702u10 > 0

select ic as IC, u as U, a10201821u10 - isnull(a10250205u10,0) as K_DISP
into #tmptable_2
from a10201132u10
where a10201821u10 is not null and a10201821u10 > 0 

update B set a40063075u10 = K_DISP, useric = 1105, useru = 0, ts0 = getdate()
from #tmptable_1 as A
join a10201132u10 as B on (B.ic = A.IC and B.u = A.U)

update B set a40063137u10 = K_DISP, useric = 1105, useru = 0, ts0 = getdate()
from #tmptable_2 as A
join a10201132u10 as B on (B.ic = A.IC and B.u = A.U)

drop table #tmptable_1
drop table #tmptable_2
</g>

<g>
select C.ic as ICSZ, C.u as USZ, A.ic_a as ICPOZ, A.u_a as UPOZ,
SUM(isnull(a40063075u10,0)) as KDISP, SUM(isnull(a40063137u10,0)) as KDISPE
into #tmptable
from a10201132u10 as A
join a234238u10 as B on (B.ic = A.ic_b and B.u = A.u_b)
join a38239u10 as C on (C.ic = B.ic_a and C.u = B.u_a)
group by C.ic, C.u, A.ic_a, A.u_a

update B set a40063077u10 = A.KDISP, a40063135u10 = A.KDISPE, useric = 1105, useru = 0, ts0 = getdate()
from #tmptable as A
join a10201123u10 as B on (B.ic_a = A.ICPOZ and B.u_a = A.UPOZ and B.ic_b = A.ICSZ and B.u_b = A.USZ)

drop table #tmptable
</g>

--LG Events converting (run)
<g>
-- Fill event order attributes
update a141u0 set a2585u0 = case a745874u10 when 1 then 10 when 2 then 30 else 20 end
update a142u0 set a2586u0 = case a745888u10 when 1 then 10 when 2 then 30 else 20 end
update a164u0 set a2587u0 = case a745916u10 when 1 then 10 when 2 then 30 else 20 end
update a195u0 set a2588u0 = case a745914u10 when 1 then 10 when 2 then 30 else 20 end
update a2195u0 set a2589u0 = case a2427u0 when 1 then 10 when 2 then 30 else 20 end
update a274890u10 set a2590u0 = case a745920u10 when 1 then 10 when 2 then 30 else 20 end
update a145u0 set a2591u0 = case a745918u10 when 1 then 10 when 2 then 30 else 20 end
-- Set event order attributes as required
update a102u0 set a244u0 = 1 where (ic > 2584 and ic < 2592) and u = 0
</g>






--LuP: NASTAVENI STAVOVYCH ATRIBUTU (NESPOUSTET)
<g>
--(1) Objednavky prijate
  --(1.1a) nastaveni atributu "Registrovano ve stavech zasob" na hodnotu 1
update A set a40167551u10=1
from a4128u10 as A
join a14954u10 as B on (B.ic_a = A.ic and B.u_a = A.u)
join a14952u10 as C on (C.ic = B.ic_b and C.u = B.u_b)
join a19300u10 as D on (D.ic_b = C.ic and D.u_b = C.u)
where (D.ic_a = 67435 and D.u_a = 10) and
      (a1400817u10 is null or a1400817u10 = 0) and
      a67415u10 in (1,6) and
      a40167551u10 is null

  --(1.1b) nastaveni atributu "Registrovano ve stavech zasob" na hodnotu 0
update A set a40167551u10=0
from a4128u10 as A
join a14954u10 as B on (B.ic_a = A.ic and B.u_a = A.u)
join a14952u10 as C on (C.ic = B.ic_b and C.u = B.u_b)
join a19300u10 as D on (D.ic_b = C.ic and D.u_b = C.u)
where (D.ic_a = 67435 and D.u_a = 10) and
      (a1400817u10 is null or a1400817u10 = 0) and
      a40167551u10 is null

  --(1.2a) nastaveni atributu "Zajistovani materialu" na hodnotu 1
update A set a40168252u10=1
from a4128u10 as A
join a14954u10 as B on (B.ic_a = A.ic and B.u_a = A.u)
join a14952u10 as C on (C.ic = B.ic_b and C.u = B.u_b)
join a19300u10 as D on (D.ic_b = C.ic and D.u_b = C.u)
where (D.ic_a = 67435 and D.u_a = 10) and
      (a1400817u10 is null or a1400817u10 = 0) and
      a67415u10 in (1,6) and
      a40168252u10 is null

  --(1.2b) nastaveni atributu "Zajistovani materialu" na hodnotu 0
update A set a40168252u10=0
from a4128u10 as A
join a14954u10 as B on (B.ic_a = A.ic and B.u_a = A.u)
join a14952u10 as C on (C.ic = B.ic_b and C.u = B.u_b)
join a19300u10 as D on (D.ic_b = C.ic and D.u_b = C.u)
where (D.ic_a = 67435 and D.u_a = 10) and
      (a1400817u10 is null or a1400817u10 = 0) and
      a40168252u10 is null

  --(1.3a) nastaveni atributu "Vstup do seznamu zbozi pro objednani" na hodnotu 1
update A set a40168250u10=1
from a4128u10 as A
join a14954u10 as B on (B.ic_a = A.ic and B.u_a = A.u)
join a14952u10 as C on (C.ic = B.ic_b and C.u = B.u_b)
join a19300u10 as D on (D.ic_b = C.ic and D.u_b = C.u)
where (D.ic_a = 67435 and D.u_a = 10) and
      (a1400817u10 is null or a1400817u10 = 0) and
      a67415u10 in (1,6) and
      a40168250u10 is null

  --(1.3b) nastaveni atributu "Vstup do seznamu zbozi pro objednani" na hodnotu 0
update A set a40168250u10=0
from a4128u10 as A
join a14954u10 as B on (B.ic_a = A.ic and B.u_a = A.u)
join a14952u10 as C on (C.ic = B.ic_b and C.u = B.u_b)
join a19300u10 as D on (D.ic_b = C.ic and D.u_b = C.u)
where (D.ic_a = 67435 and D.u_a = 10) and
      (a1400817u10 is null or a1400817u10 = 0) and
      a40168250u10 is null

--(2) Interni objednavky prijate
  --(2.1a) nastaveni atributu "Registrovano ve stavech zasob" na hodnotu 1
update A set a40167551u10=1
from a4128u10 as A
join a14954u10 as B on (B.ic_a = A.ic and B.u_a = A.u)
join a14952u10 as C on (C.ic = B.ic_b and C.u = B.u_b)
join a19300u10 as D on (D.ic_b = C.ic and D.u_b = C.u)
where (D.ic_a = 67435 and D.u_a = 10) and
      (a1400817u10 is not null and a1400817u10 = 1) and
      a67415u10 in (1,6) and
      a40167551u10 is null

  --(2.1b) nastaveni atributu "Registrovano ve stavech zasob" na hodnotu 0
update A set a40167551u10=0
from a4128u10 as A
join a14954u10 as B on (B.ic_a = A.ic and B.u_a = A.u)
join a14952u10 as C on (C.ic = B.ic_b and C.u = B.u_b)
join a19300u10 as D on (D.ic_b = C.ic and D.u_b = C.u)
where (D.ic_a = 67435 and D.u_a = 10) and
      (a1400817u10 is not null and a1400817u10 = 1) and
      a40167551u10 is null

  --(2.2a) nastaveni atributu "Zajistovani materialu" na hodnotu 1
update A set a40168252u10=1
from a4128u10 as A
join a14954u10 as B on (B.ic_a = A.ic and B.u_a = A.u)
join a14952u10 as C on (C.ic = B.ic_b and C.u = B.u_b)
join a19300u10 as D on (D.ic_b = C.ic and D.u_b = C.u)
where (D.ic_a = 67435 and D.u_a = 10) and
      (a1400817u10 is not null and a1400817u10 = 1) and
      a67415u10 in (1,6) and
      a40168252u10 is null

  --(2.2b) nastaveni atributu "Zajistovani materialu" na hodnotu 0
update A set a40168252u10=0
from a4128u10 as A
join a14954u10 as B on (B.ic_a = A.ic and B.u_a = A.u)
join a14952u10 as C on (C.ic = B.ic_b and C.u = B.u_b)
join a19300u10 as D on (D.ic_b = C.ic and D.u_b = C.u)
where (D.ic_a = 67435 and D.u_a = 10) and
      (a1400817u10 is not null and a1400817u10 = 1) and
      a40168252u10 is null

  --(2.3a) nastaveni atributu "Vstup do seznamu zbozi pro objednani" na hodnotu 1
update A set a40168250u10=1
from a4128u10 as A
join a14954u10 as B on (B.ic_a = A.ic and B.u_a = A.u)
join a14952u10 as C on (C.ic = B.ic_b and C.u = B.u_b)
join a19300u10 as D on (D.ic_b = C.ic and D.u_b = C.u)
where (D.ic_a = 67435 and D.u_a = 10) and
      (a1400817u10 is not null and a1400817u10 = 1) and
      a67415u10 in (1,6) and
      a40168250u10 is null

  --(2.3b) nastaveni atributu "Vstup do seznamu zbozi pro objednani" na hodnotu 1
update A set a40168250u10=0
from a4128u10 as A
join a14954u10 as B on (B.ic_a = A.ic and B.u_a = A.u)
join a14952u10 as C on (C.ic = B.ic_b and C.u = B.u_b)
join a19300u10 as D on (D.ic_b = C.ic and D.u_b = C.u)
where (D.ic_a = 67435 and D.u_a = 10) and
      (a1400817u10 is not null and a1400817u10 = 1) and
      a40168250u10 is null

--(3) Proforma-fakury
  --(3.1a) nastaveni atributu "Registrovano ve stavech zasob" na hodnotu 1
update A set a40167551u10=1
from a4128u10 as A
join a14954u10 as B on (B.ic_a = A.ic and B.u_a = A.u)
join a14952u10 as C on (C.ic = B.ic_b and C.u = B.u_b)
join a19300u10 as D on (D.ic_b = C.ic and D.u_b = C.u)
where (D.ic_a = 189051 and D.u_a = 10) and
      a67415u10 in (1,6) and
      a40167551u10 is null

  --(3.1b) nastaveni atributu "Registrovano ve stavech zasob" na hodnotu 0
update A set a40167551u10=0
from a4128u10 as A
join a14954u10 as B on (B.ic_a = A.ic and B.u_a = A.u)
join a14952u10 as C on (C.ic = B.ic_b and C.u = B.u_b)
join a19300u10 as D on (D.ic_b = C.ic and D.u_b = C.u)
where (D.ic_a = 189051 and D.u_a = 10) and
      a40167551u10 is null

  --(3.2a) nastaveni atributu "Zajistovani materialu" na hodnotu 1
update A set a40168252u10=1
from a4128u10 as A
join a14954u10 as B on (B.ic_a = A.ic and B.u_a = A.u)
join a14952u10 as C on (C.ic = B.ic_b and C.u = B.u_b)
join a19300u10 as D on (D.ic_b = C.ic and D.u_b = C.u)
where (D.ic_a = 189051 and D.u_a = 10) and
      a67415u10 in (1,6) and
      a40168252u10 is null

  --(3.2b) nastaveni atributu "Zajistovani materialu" na hodnotu 0
update A set a40168252u10=0
from a4128u10 as A
join a14954u10 as B on (B.ic_a = A.ic and B.u_a = A.u)
join a14952u10 as C on (C.ic = B.ic_b and C.u = B.u_b)
join a19300u10 as D on (D.ic_b = C.ic and D.u_b = C.u)
where (D.ic_a = 189051 and D.u_a = 10) and
      a40168252u10 is null

  --(3.3a) nastaveni atributu "Vstup do seznamu zbozi pro objednani" na hodnotu 1
update A set a40168250u10=1
from a4128u10 as A
join a14954u10 as B on (B.ic_a = A.ic and B.u_a = A.u)
join a14952u10 as C on (C.ic = B.ic_b and C.u = B.u_b)
join a19300u10 as D on (D.ic_b = C.ic and D.u_b = C.u)
where (D.ic_a = 189051 and D.u_a = 10) and
      a67415u10 in (1,6) and
      a40168250u10 is null

  --(3.3b) nastaveni atributu "Vstup do seznamu zbozi pro objednani" na hodnotu 1
update A set a40168250u10=0
from a4128u10 as A
join a14954u10 as B on (B.ic_a = A.ic and B.u_a = A.u)
join a14952u10 as C on (C.ic = B.ic_b and C.u = B.u_b)
join a19300u10 as D on (D.ic_b = C.ic and D.u_b = C.u)
where (D.ic_a = 189051 and D.u_a = 10) and
      a40168250u10 is null

--(4) Objednavky vydane
  --(4.1a) nastaveni atributu "Registrovano ve stavech zasob" na hodnotu 1
update A set a40168020u10=1
from a4132u10 as A
join a14954u10 as B on (B.ic_a = A.ic and B.u_a = A.u)
join a14952u10 as C on (C.ic = B.ic_b and C.u = B.u_b)
join a19300u10 as D on (D.ic_b = C.ic and D.u_b = C.u)
where (D.ic_a = 41899 and D.u_a = 10) and
      (a1400817u10 is null or a1400817u10 = 0) and
      a69193u10 in (5) and
      a40168020u10 is null

  --(4.1b) nastaveni atributu "Registrovano ve stavech zasob" na hodnotu 0
update A set a40168020u10=0
from a4132u10 as A
join a14954u10 as B on (B.ic_a = A.ic and B.u_a = A.u)
join a14952u10 as C on (C.ic = B.ic_b and C.u = B.u_b)
join a19300u10 as D on (D.ic_b = C.ic and D.u_b = C.u)
where (D.ic_a = 41899 and D.u_a = 10) and
      (a1400817u10 is null or a1400817u10 = 0) and
      a40168020u10 is null

  --(4.2a) nastaveni atributu "Zajistovani materialu" na hodnotu 1
update A set a40168256u10=1
from a4132u10 as A
join a14954u10 as B on (B.ic_a = A.ic and B.u_a = A.u)
join a14952u10 as C on (C.ic = B.ic_b and C.u = B.u_b)
join a19300u10 as D on (D.ic_b = C.ic and D.u_b = C.u)
where (D.ic_a = 41899 and D.u_a = 10) and
      (a1400817u10 is null or a1400817u10 = 0) and
      a69193u10 in (0,1,5) and
      a40168256u10 is null

  --(4.2b) nastaveni atributu "Zajistovani materialu" na hodnotu 0
update A set a40168256u10=0
from a4132u10 as A
join a14954u10 as B on (B.ic_a = A.ic and B.u_a = A.u)
join a14952u10 as C on (C.ic = B.ic_b and C.u = B.u_b)
join a19300u10 as D on (D.ic_b = C.ic and D.u_b = C.u)
where (D.ic_a = 41899 and D.u_a = 10) and
      (a1400817u10 is null or a1400817u10 = 0) and
      a40168256u10 is null

  --(4.3a) nastaveni atributu "Vstup do seznamu zbozi pro objednani" na hodnotu 1
update A set a40168254u10=1
from a4132u10 as A
join a14954u10 as B on (B.ic_a = A.ic and B.u_a = A.u)
join a14952u10 as C on (C.ic = B.ic_b and C.u = B.u_b)
join a19300u10 as D on (D.ic_b = C.ic and D.u_b = C.u)
where (D.ic_a = 41899 and D.u_a = 10) and
      (a1400817u10 is null or a1400817u10 = 0) and
      a69193u10 in (1) and
      a40168254u10 is null

  --(4.3b) nastaveni atributu "Vstup do seznamu zbozi pro objednani" na hodnotu 0
update A set a40168254u10=0
from a4132u10 as A
join a14954u10 as B on (B.ic_a = A.ic and B.u_a = A.u)
join a14952u10 as C on (C.ic = B.ic_b and C.u = B.u_b)
join a19300u10 as D on (D.ic_b = C.ic and D.u_b = C.u)
where (D.ic_a = 41899 and D.u_a = 10) and
      (a1400817u10 is null or a1400817u10 = 0) and
      a40168254u10 is null

--(5) Interni objednavky vydane
  --(5.1a) nastaveni atributu "Registrovano ve stavech zasob" na hodnotu 1
update A set a40168020u10=1
from a4132u10 as A
join a14954u10 as B on (B.ic_a = A.ic and B.u_a = A.u)
join a14952u10 as C on (C.ic = B.ic_b and C.u = B.u_b)
join a19300u10 as D on (D.ic_b = C.ic and D.u_b = C.u)
where (D.ic_a = 41899 and D.u_a = 10) and
      (a1400817u10 is not null and a1400817u10 = 1) and
      (a8073446u10 is null or a8073446u10 = 0) and
      a69193u10 in (5) and
      a40168020u10 is null

  --(5.1b) nastaveni atributu "Registrovano ve stavech zasob" na hodnotu 0
update A set a40168020u10=0
from a4132u10 as A
join a14954u10 as B on (B.ic_a = A.ic and B.u_a = A.u)
join a14952u10 as C on (C.ic = B.ic_b and C.u = B.u_b)
join a19300u10 as D on (D.ic_b = C.ic and D.u_b = C.u)
where (D.ic_a = 41899 and D.u_a = 10) and
      (a1400817u10 is not null and a1400817u10 = 1) and
      (a8073446u10 is null or a8073446u10 = 0) and
      a40168020u10 is null

  --(5.2a) nastaveni atributu "Vstup do seznamu zbozi pro objednani" na hodnotu 1
update A set a40168254u10=1
from a4132u10 as A
join a14954u10 as B on (B.ic_a = A.ic and B.u_a = A.u)
join a14952u10 as C on (C.ic = B.ic_b and C.u = B.u_b)
join a19300u10 as D on (D.ic_b = C.ic and D.u_b = C.u)
where (D.ic_a = 41899 and D.u_a = 10) and
      (a1400817u10 is not null and a1400817u10 = 1) and
      (a8073446u10 is null or a8073446u10 = 0) and
      a69193u10 in (1) and
      a40168254u10 is null

  --(5.2b) nastaveni atributu "Vstup do seznamu zbozi pro objednani" na hodnotu 0
update A set a40168254u10=0
from a4132u10 as A
join a14954u10 as B on (B.ic_a = A.ic and B.u_a = A.u)
join a14952u10 as C on (C.ic = B.ic_b and C.u = B.u_b)
join a19300u10 as D on (D.ic_b = C.ic and D.u_b = C.u)
where (D.ic_a = 41899 and D.u_a = 10) and
      (a1400817u10 is not null and a1400817u10 = 1) and
      (a8073446u10 is null or a8073446u10 = 0) and
      a40168254u10 is null

--(6) Pozadavky na material
  --(6.1a) nastaveni atributu "Registrovano ve stavech zasob" na hodnotu 1
update A set a40168020u10=1
from a4132u10 as A
join a14954u10 as B on (B.ic_a = A.ic and B.u_a = A.u)
join a14952u10 as C on (C.ic = B.ic_b and C.u = B.u_b)
join a19300u10 as D on (D.ic_b = C.ic and D.u_b = C.u)
where (D.ic_a = 41899 and D.u_a = 10) and
      (a1400817u10 is not null and a1400817u10 = 1) and
      (a8073446u10 is not null and a8073446u10 in (1,2)) and
      a69193u10 in (1) and
      a40168020u10 is null

  --(6.1b) nastaveni atributu "Registrovano ve stavech zasob" na hodnotu 0
update A set a40168020u10=0
from a4132u10 as A
join a14954u10 as B on (B.ic_a = A.ic and B.u_a = A.u)
join a14952u10 as C on (C.ic = B.ic_b and C.u = B.u_b)
join a19300u10 as D on (D.ic_b = C.ic and D.u_b = C.u)
where (D.ic_a = 41899 and D.u_a = 10) and
      (a1400817u10 is not null and a1400817u10 = 1) and
      (a8073446u10 is not null and a8073446u10 in (1,2)) and
      a40168020u10 is null

  --(6.2a) nastaveni atributu "Zajistovani materialu" na hodnotu 1
update A set a40168256u10=1
from a4132u10 as A
join a14954u10 as B on (B.ic_a = A.ic and B.u_a = A.u)
join a14952u10 as C on (C.ic = B.ic_b and C.u = B.u_b)
join a19300u10 as D on (D.ic_b = C.ic and D.u_b = C.u)
where (D.ic_a = 41899 and D.u_a = 10) and
      (a1400817u10 is not null and a1400817u10 = 1) and
      (a8073446u10 is not null and a8073446u10 in (1,2)) and
      a69193u10 in (1) and
      a40168256u10 is null

  --(6.2b) nastaveni atributu "Zajistovani materialu" na hodnotu 0
update A set a40168256u10=0
from a4132u10 as A
join a14954u10 as B on (B.ic_a = A.ic and B.u_a = A.u)
join a14952u10 as C on (C.ic = B.ic_b and C.u = B.u_b)
join a19300u10 as D on (D.ic_b = C.ic and D.u_b = C.u)
where (D.ic_a = 41899 and D.u_a = 10) and
      (a1400817u10 is not null and a1400817u10 = 1) and
      (a8073446u10 is not null and a8073446u10 in (1,2)) and
      a40168256u10 is null

  --(6.3a) nastaveni atributu "Vstup do seznamu zbozi pro objednani" na hodnotu 1
update A set a40168254u10=1
from a4132u10 as A
join a14954u10 as B on (B.ic_a = A.ic and B.u_a = A.u)
join a14952u10 as C on (C.ic = B.ic_b and C.u = B.u_b)
join a19300u10 as D on (D.ic_b = C.ic and D.u_b = C.u)
where (D.ic_a = 41899 and D.u_a = 10) and
      (a1400817u10 is not null and a1400817u10 = 1) and
      (a8073446u10 is not null and a8073446u10 in (1,2)) and
      a69193u10 in (1) and
      a40168254u10 is null

  --(6.3b) nastaveni atributu "Vstup do seznamu zbozi pro objednani" na hodnotu 0
update A set a40168254u10=0
from a4132u10 as A
join a14954u10 as B on (B.ic_a = A.ic and B.u_a = A.u)
join a14952u10 as C on (C.ic = B.ic_b and C.u = B.u_b)
join a19300u10 as D on (D.ic_b = C.ic and D.u_b = C.u)
where (D.ic_a = 41899 and D.u_a = 10) and
      (a1400817u10 is not null and a1400817u10 = 1) and
      (a8073446u10 is not null and a8073446u10 in (1,2)) and
      a40168254u10 is null

--(7) Ramcove objednavky prijate
  --(7.1a) nastaveni atributu "Vstup do seznamu zbozi pro objednani" na hodnotu 1
update A set a40168250u10=1
from a4128u10 as A
join a14954u10 as B on (B.ic_a = A.ic and B.u_a = A.u)
join a14952u10 as C on (C.ic = B.ic_b and C.u = B.u_b)
join a19300u10 as D on (D.ic_b = C.ic and D.u_b = C.u)
where (D.ic_a = 22441079 and D.u_a = 10) and
      a67415u10 in (1,6) and
      a40168250u10 is null

  --(7.1b) nastaveni atributu "Vstup do seznamu zbozi pro objednani" na hodnotu 0
update A set a40168250u10=0
from a4128u10 as A
join a14954u10 as B on (B.ic_a = A.ic and B.u_a = A.u)
join a14952u10 as C on (C.ic = B.ic_b and C.u = B.u_b)
join a19300u10 as D on (D.ic_b = C.ic and D.u_b = C.u)
where (D.ic_a = 22441079 and D.u_a = 10) and
      a40168250u10 is null

--(8) Ramcove objednavky vydane
  --(8.1a) nastaveni atributu "Vstup do seznamu zbozi pro objednani" na hodnotu 1
update A set a40168254u10=1
from a4132u10 as A
join a14954u10 as B on (B.ic_a = A.ic and B.u_a = A.u)
join a14952u10 as C on (C.ic = B.ic_b and C.u = B.u_b)
join a19300u10 as D on (D.ic_b = C.ic and D.u_b = C.u)
where (D.ic_a = 22441078 and D.u_a = 10) and
      a69193u10 in (1) and
      a40168254u10 is null

  --(8.1b) nastaveni atributu "Vstup do seznamu zbozi pro objednani" na hodnotu 0
update A set a40168254u10=0
from a4132u10 as A
join a14954u10 as B on (B.ic_a = A.ic and B.u_a = A.u)
join a14952u10 as C on (C.ic = B.ic_b and C.u = B.u_b)
join a19300u10 as D on (D.ic_b = C.ic and D.u_b = C.u)
where (D.ic_a = 22441078 and D.u_a = 10) and
      a40168254u10 is null
</g>


-- Doprava: konretni statky ovlivnene akci - API klic - Nespoustet
<g>
update a1159214u10
set useric = 1105, useru = 0, ts0 = getdate(), a1058807u10212 = remotekey, remotekey = null
where a1058807u10212 is null and remotekey is not null
</g>

-- WMS: blokace manilupacni jednotky - vytvorena
<g>
update blok
set useric = 1105, useru = 0, ts0 = getdate(), a461635u11011 = case when fix.ic is null and a381656u11011 = 1 then 1 end
from
  a381503u11011 blok
  left outer join a30640917u10 fix on blok.ic_b = fix.ic and blok.u_b = fix.u
where
  a461635u11011 is null
</g>

-- definice davky: skladova zasoba
<g>
update a139128u11011 set useric = 1105, useru = 0, ts0 = getdate(),
  a463997u11011 = case
	-- premisteni bez zdroje: volna
	when a139132u11011 = 3 and (a167269u11011 = 0 or a167269u11011 = 3) then 2
	-- doklad, polozky, davka: aktualni
	when a167269u11011 = 1 or a167269u11011 = 7 or a167269u11011 = 4 then 1
	-- ostatni: disponibilni
	else 3
  end
where (a139132u11011 = 1 or a139132u11011 = 3 or a139132u11011 = 4 or a139132u11011 = 5 or a139132u11011 = 7) and a463997u11011 is null
</g>

-- polozka davky: rucni vlozeni
<g>
update batchItems set a464533u11011 = 1
from
  a139392u11011 batchItems
  left outer join a237290u11011 sourcePlace on sourcePlace.ic_a = batchItems.ic and sourcePlace.u_a = batchItems.u and a237314u11011 = 1
  left outer join a237291u11011 targetPlace on targetPlace.ic_a = batchItems.ic and targetPlace.u_a = batchItems.u and a237320u11011 = 1
  left outer join a139552u11011 sourceDocItem on sourceDocItem.ic_a = batchItems.ic and sourceDocItem.u_a = batchItems.u
  left outer join a179056u11011 sourceBatchItem on sourceBatchItem.ic_a = batchItems.ic and sourceBatchItem.u_a = batchItems.u
where
  a464533u11011 is null and sourcePlace.ic is null and targetPlace.ic is null and sourceDocItem.ic is null and sourceBatchItem.ic is null
</g>



--KaSo oprava 
<g>
delete from a189240u10 where ic_a = 961000 and u_a = 10
</g>

